import 'dart:math';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
// import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:totaldemo/config/big_%20branch.dart';
import 'package:totaldemo/config/net_course.dart';
import 'package:totaldemo/config/practice.dart';
import 'package:totaldemo/config/project.dart';
import 'package:totaldemo/getx/bingdings.dart';
import 'package:totaldemo/getx/getx_home.dart';
import 'package:totaldemo/pages/ListView_disPlay.dart';
import 'package:totaldemo/pages/bottom_sheet.dart';
// import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:totaldemo/pages/bri.dart';
import 'package:totaldemo/pages/clickSubItem.dart';
import 'package:totaldemo/pages/evaluation/my_diss.dart';
import 'package:totaldemo/practice/jpush.dart';
import 'package:totaldemo/practice/seekBar.dart';
import 'package:totaldemo/practice/seekbar2.dart';
import 'package:totaldemo/practice/tabBar.dart';
import 'package:totaldemo/practice/textField.dart';
import 'package:totaldemo/practice/use_slider.dart';
import 'package:totaldemo/utils/util.dart';
// import 'package:totaldemo/wangyi_news/wangyi_home.dart';
// import 'package:flutter_localizations/flutter_localizations.dart';
import 'config/init_config.dart';
import 'utils/screen_unit.dart';
import 'package:jverify/jverify.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

void main() {
  ///配置初始化
  InitConfig.instance();
  // WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(375, 812),
      builder: () => GetMaterialApp(
        initialBinding: ControllerBindings(),
        debugShowCheckedModeBanner: false,
        // localizationsDelegates: [
        //   GlobalMaterialLocalizations.delegate,
        //   GlobalWidgetsLocalizations.delegate,
        // ],
        // here
        navigatorObservers: [FlutterSmartDialog.observer],
        // here
        builder: FlutterSmartDialog.init(),
        title: '知知脏的demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // final JPush jpush = JPush();
  final Jverify s = Jverify();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // initPlatformState(); //极光平台初始化
    ///高德地图初始化
  }

  // Future<void> initPlatformState() async {
  //   try {
  //     jpush.addEventHandler(
  //         onReceiveNotification: (Map<String, dynamic> message) async {
  //       print("flutter onReceiveNotification: $message");
  //       print(">>>>>>>>>>>>>>>>>flutter 接收到推送: $message");
  //     }, onOpenNotification: (Map<String, dynamic> message) async {
  //       print("flutter onOpenNotification: $message");
  //     }, onReceiveMessage: (Map<String, dynamic> message) async {
  //       print("flutter onReceiveMessage: $message");
  //     }, onReceiveNotificationAuthorization:
  //             (Map<String, dynamic> message) async {
  //       print("flutter onReceiveNotificationAuthorization: $message");
  //     });
  //   } on PlatformException {}

  //   // Jverify.setup(
  //   //   appKey: "b9551c2f6d171e4ff32b57c9", //你自己应用的 AppKey
  //   //   channel: "jpush_demo",
  //   //   production: false,
  //   //   debug: true,
  //   // );

  //   jpush.setup(
  //     appKey: "b9551c2f6d171e4ff32b57c9", //你自己应用的 AppKey
  //     channel: "jpush_demo",
  //     production: false,
  //     debug: true,
  //   );

  //   jpush.getRegistrationID().then((rid) {
  //     print("当前设备的rid： $rid");
  //   });
  //   jpush.applyPushAuthority(
  //       new NotificationSettingsIOS(sound: true, alert: true, badge: true));

  //   // Platform messages may fail, so we use a try/catch PlatformException.
  //   jpush.getRegistrationID().then((rid) {
  //     print("flutter get registration id : $rid");
  //   });

  //   // If the widget was removed from the tree while the asynchronous platform
  //   // message was in flight, we want to discard the reply rather than calling
  //   // setState to update our non-existent appearance.
  //   // if (!mounted) return;
  // }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // resizeToAvoidBottomInset: true,
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Stack(
        children: [
          Container(
            height: Get.height * .45,
            decoration: BoxDecoration(
              color: Color(0xFFF5CEB8),
            ),
            child: Row(
              children: [
                Image.asset(
                  Util.getUrl('logo.png'),
                  width: 100,
                  height: 100,
                ),
                SizedBox(
                  width: 30,
                ),
                Text('知知脏的demo', style: Theme.of(context).textTheme.headline5),
              ],
            ),
          ),
          Padding(
            padding:
                EdgeInsets.only(top: Get.height * .35, left: 20, right: 20),
            child: GridView.count(
              crossAxisCount: 2,
              shrinkWrap: false,
              physics: NeverScrollableScrollPhysics(),
              childAspectRatio: 1.3,
              crossAxisSpacing: 10,
              mainAxisSpacing: 10,
              children: <Widget>[
                CardWidget(
                  title: '日常练习',
                  icon: Icons.inbox_outlined,
                  onTap: () {
                    Get.to(() => PracticePage());
                  },
                ),
                CardWidget(
                  title: '项目所用',
                  icon: Icons.person,
                  onTap: () {
                    Get.to(() => ProjectPage());
                  },
                ),
                CardWidget(
                  title: '网络课程',
                  icon: Icons.indeterminate_check_box,
                  onTap: () {
                    Get.to(() => NetCoursePage());
                  },
                ),
                CardWidget(
                  title: '独立区块',
                  icon: Icons.alarm_outlined,
                  onTap: () {
                    Get.to(() => Bigbranch());
                  },
                ),
              ],
            ),
          ),
        ],
      ),
      // body: LayoutBuilder(
      //     builder: (BuildContext context, BoxConstraints constraints) {
      //   print(constraints);
      //   return Container(
      //     color: Colors.red,
      //     height: constraints.maxHeight / 2,
      //     child: Row(
      //       mainAxisAlignment: MainAxisAlignment.center,
      //       children: [
      //         FlutterLogo(),
      //         Text(
      //           '知知脏的demo',
      //           style: TextStyle(fontSize: 40),
      //         ),
      //       ],
      //     ),
      //   );
      // }),

      // ListView(
      //   children: [
      //     Wrap(
      //       // mainAxisAlignment: MainAxisAlignment.start,
      //       direction: Axis.horizontal,
      //       spacing: 10.w,
      //       runSpacing: 10.w,
      //       children: <Widget>[

      //         Divider(),

      //         Divider(),

      //         ElevatedButton(
      //           onPressed: () {
      //             Get.to(UseSliderPage());
      //           },
      //           child: Text('自定义slider'),
      //         ),
      //       ],
      //     ),
      //   ],
      // ),
    );
  }
}

class CardWidget extends StatelessWidget {
  final String title;
  final IconData icon;
  final GestureTapCallback onTap;
  const CardWidget({Key key, this.title, this.icon, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.all(5),
        decoration: BoxDecoration(
            border: Border.all(color: Colors.grey.withOpacity(0.2)),
            borderRadius: BorderRadius.circular(13),
            color: Colors.white),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // Spacer(),
            Icon(
              icon,
              size: 45,
              color: Colors.amber,
            ),
            // Spacer(),
            SizedBox(
              height: 1,
            ),
            Text(title,
                style: Theme.of(context).textTheme.headline6?.copyWith(
                      fontSize: 15,
                    )),
            SizedBox(
              height: 2,
            ),
          ],
        ),
      ),
    );
  }
}
